package org.cydonia.daemon;

import java.util.Timer;
import org.cydonia.config.Configuration;
import org.cydonia.misc.StrUtil;

/**
 *
 * @author franklin
 */
public class Daemon {

    private int MINUTES;
    
    private String INIT_MESSAGE;

    public Daemon(Configuration c) {
        String updateTime = c.getValue(Configuration.UPDATETIME);
        if (StrUtil.nvl(updateTime).equals("")) {
            System.out.println("Exiting... no interval especified in .conf file");
            this.INIT_MESSAGE = "No startup daemon success.";
            System.exit(0);
        } else {
            this.setMINUTES(Integer.parseInt(updateTime) * 1000 * 60);
            Timer timer = new Timer();
            timer.schedule(new TimerTask(c), 0, this.getMINUTES());
            this.INIT_MESSAGE = "Cydonia Startup Daemon OK! Refresh time is "+updateTime+" minutes.";
            System.out.println(this.INIT_MESSAGE);
        }
    }

    public int getMINUTES() {
        return MINUTES;
    }

    public void setMINUTES(int MINUTES) {
        this.MINUTES = MINUTES;
    }

    public String getINIT_MESSAGE() {
        return INIT_MESSAGE;
    }
    
}
